# -*- coding = utf-8 -*-
# @Time    : 2025/3/28 下午6:58
# @Author  : yqk
# @File    : study_bs4.py
# @Software: PyCharm

from bs4 import BeautifulSoup

html = '''
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/title" class="sister" id="link2">Lacie</a>;
and they lived at .</p>
# 
'''
soup = BeautifulSoup(html, 'html.parser')
# print(soup.prettify())
# # 获取标签
# print(soup.a)
# # 获取标签名称
# print(soup.a.name)
# # 获取标签属性
# print(soup.a.attrs)
# print(soup.a['href'])
# print(soup.a.get('href'))
# # 改变标签属性
# soup.a['href'] = 'https://www.baidu.com'
# print(soup.a)
# # 获取标签文本内容
# print(soup.a.string)

# body_tag = soup.body
# print(body_tag.contents)
# for child in body_tag.children:
#     print(child)
#
# for child in body_tag.strings:
#     print(child)

